﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Helena.Areas.Clientes.Models;
using Telerik.Web.Mvc;
using Helena.Areas.Vendedores.Models;

namespace Helena.Areas.Clientes.Controllers
{
    public class ClienteController : Controller
    {
        LogicaCliente db = new LogicaCliente();

        #region Comun

        public ActionResult Index()
        {
            VendedorView vw = (VendedorView)Session["Vendedor"];
            if (vw.ID != 0)
            {
                return View("IndexCliente");
            }
            else
            {
                return Redirect("../Home/NoSession");
            }
            
        }

        [GridAction]
        public ActionResult Select()
        {
            return View("Index", new GridModel(db.i_RetornarClientes()));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult Insert()
        {

            ClienteView c_v = new ClienteView();
            if (TryUpdateModel(c_v))
            {
                c_v.Estado = true;
                db.i_AgregarCliente(c_v);
            }
            return View("Index", new GridModel(db.i_RetornarClientes()));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult Delete(int? id)
        {
            int ID = id ?? -1;
            db.i_EliminarCliente(ID);
            return View("Index", new GridModel(db.i_RetornarClientes()));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult Update(ClienteView c)
        {
            db.i_ModificarCliente(c);
            return View("Index", new GridModel(db.i_RetornarClientes()));
        }
        #endregion

    }
}
